home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
tvalt.exe
/
TEXT.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-05
|
4KB
|
156 lines
#include <dos.h>
#include <tv.h>
#define HIBYTE(x) ( ((x) >> 8) & 0xFF )
#define LOBYTE(x) ( (x) & 0xFF )
#define BGATTR(x) ( ((HIBYTE(x)) >> 4) & 0x0F )
#define FGATTR(x) ( (HIBYTE(x)) & 0x0F )
static unsigned char strbuf[100];
extern unsigned char shadowAttr;
// function: paintChars
// declaration:
// short paintChars( short x, short y, short max, ushort *buf );
// where:
// x = start column (in chars) : 0-based.
// y = row (in chars) : 0-based.
// max = max length of buf.
// buf = char/attr buffer.
// paintChars() optimizes BIOS calls by searching buf for all the entries
// (up to max) that have the same character and attribute, then using
// the video BIOS (interrupt 10h) to draw these chars on the screen.
// Returns the number of entries printed.
static short paintChars( short x, short y, short max, ushort *buf )
{
ushort item = *buf;
short count = 0;
while( count < max && buf[count] == item )
count++;
// Move the cursor to the starting location.
_BH = 0;
_DH = (uchar)y;
_DL = (uchar)x;
_AH = 2;
geninterrupt(0x10);
// print 'count' copies of item to the screen.
uchar ch = (uchar)LOBYTE(item);
uchar attr = (uchar)HIBYTE(item);
_CX = count;
_BL = attr;
_BH = 0;
_AL = ch;
_AH = 9;
geninterrupt(0x10);
return count;
}
// function: paintSChars
// declaration:
// short paintSChars( short x, short y, short max, ushort *buf );
// where:
// x = start column (in chars) : 0-based.
// y = row (in chars) : 0-based.
// max = max length of buf.
// buf = char/attr buffer.
// paintSChars() optimizes BIOS calls by searching buf for all the entries
// (up to max) that have the same character, then using the video BIOS
// (interrupt 10h) to draw these chars on the screen using the shadowAttr
// attribute. Returns the number of entries printed.
static short paintSChars( short x, short y, short max, ushort *buf )
{
ushort item = *buf;
ushort theChar = LOBYTE(item);
short count = 0;
while( count < max && LOBYTE(buf[count]) == theChar )
count++;
_BH = 0;
_DH = (uchar)y;
_DL = (uchar)x;
_AH = 2;
geninterrupt(0x10);
uchar ch = (uchar)theChar;
uchar attr = (uchar)shadowAttr;
_CX = count;
_BL = attr;
_BH = 0;
_AL = ch;
_AH = 9;
geninterrupt(0x10);
return count;
}
// function: altWriteMethod
// declaration:
// void altWriteMethod(short x, short y, short wid, ushort *buf,
// short sflag);
// where:
// x = start column (in chars) : 0-based.
// y = row (in chars) : 0-based.
// wid = size of buf.
// buf = char/attrib data buffer.
// sflag = 0 if attrib in buf should be used, <>0 if shadowAttr should
// be used.
void altWriteMethod( short x, short y, short wid, ushort *buf, short sflag )
{
ushort *pbuf;
short iw, count;
ushort oldpos, oldshape;
// Save the old cursor shape/position.
_BH = 0;
_AH = 3;
geninterrupt(0x10);
oldpos = _DX;
oldshape = _CX;
// Hide the cursor
_CX = 0x2020;
_AH = 1;
geninterrupt(0x10);
if( !sflag ) // use attrib data in buf.
{
pbuf = buf;
iw = wid;
while( iw > 0 )
{
count = paintChars( x, y, iw, pbuf );
x += count;
pbuf += count;
iw -= count;
}
}
else // use shadowAttr.
{
pbuf = buf;
iw = wid;
while( iw > 0 )
{
count = paintSChars( x, y, iw, pbuf );
x += count;
pbuf += count;
iw -= count;
}
}
// Restore the cursor position.
_DX = oldpos;
_BH = 0;
_AH = 2;
geninterrupt(0x10);
// Un-hide the cursor.
_CX = oldshape;
_AH = 1;
geninterrupt(0x10);
}